import java.util.Scanner;
public class E1 {
    //读取数据创建链表,返回链表头结点
    public static ListNode createList(String nums[]) {
        ListNode dummy = new ListNode(1000000,1000000);
        for (int i = 0; i < nums.length-2; i+=2) {
            ListNode cur = dummy;
            ListNode newNode = new ListNode(Integer.valueOf(nums[i]),Integer.valueOf(nums[i+1]));
            //连接第一个目标结点
            if(cur.next==null) {
                cur.next = newNode;
                continue;
            }
            //连接后面的结点
            while(cur!=null) {
                ListNode curNext = cur.next;
                //按次数降序排列
                if(cur.pow>newNode.pow && curNext.pow<newNode.pow) {
                    cur.next = newNode;
                    newNode.next = curNext;
                    cur = curNext;
                    break;
                }else {
                    cur = curNext;
                    //处理连接最后一个结点的情况
                    if(cur.next == null) {
                        cur.next = newNode;
                        break;
                    }
                }
            }
        }
        return dummy.next;
    }
    //拼接答案字符串
    public static void appendRes(StringBuilder stringBuilder,int coef,int pow) {
        if(pow==0) {
            stringBuilder.append(coef+"");
            return;
        }
        if(coef==1) {
            stringBuilder.append("x^"+pow);
        }else {
            stringBuilder.append(coef+"x^"+pow);
        }
    }
    public static void main(String[] args) {
        //1.初始化读取处理数组
        String[] nums1;String[] nums2;
        Scanner scanner = new Scanner(System.in);
        nums1 = scanner.nextLine().split(" ");
        scanner.nextLine();
        nums2 = scanner.nextLine().split(" ");
        //2.创建链表获得头节点
        ListNode head1 = createList(nums1);
        ListNode head2 = createList(nums2);
        //3.获得结果
        StringBuilder stringBuilder = new StringBuilder();
        ListNode cur1 = head1;ListNode cur2 = head2;
        ListNode head = new ListNode(100000,100000);
        ListNode cur = head;
        while(cur1!=null&&cur2!=null) {
            //先处理次数大的结点
            if(cur1.pow>cur2.pow) {
                cur.next = cur1;
                cur1 = cur1.next;
                cur = cur.next;
            }else if(cur1.pow<cur2.pow) {
                cur.next = cur2;
                cur2= cur2.next;
                cur = cur.next;
            }else {
                cur.next = new ListNode(cur1.coef+cur2.coef,cur1.pow);
                cur1 = cur1.next;
                cur2 = cur2.next;
                cur = cur.next;
            }
        }
        //处理剩下的不为空的链表
        ListNode notNullNode = (cur1==null)?cur2:cur1;
        while(notNullNode!=null) {
            cur.next = notNullNode;
            notNullNode = notNullNode.next;
        }
        //遍历最后的链表
        cur = head.next;
        while(cur!=null) {
            appendRes(stringBuilder,cur.coef,cur.pow);
            cur = cur.next;
            stringBuilder.append("+");
        }
        //处理最后的加号
        if(stringBuilder.lastIndexOf("+")==stringBuilder.length()-1) {
            System.out.println(stringBuilder.toString().substring(0,stringBuilder.toString().length()-1));
        }else {
            System.out.println(stringBuilder);
        }
    }
}
